import { View } from "@tarojs/components";
import { useRouter } from "@tarojs/taro";
//import "./index.scss";

import { useCallContainerGet } from "@/tools/useCallContainer";

import Taro from "@tarojs/taro";  
import SearchBar from "@/components/SearchBar";
import RestaurantItem from "../index/components/RestaurantItem";

export default function searchResturant() {
  const { params } = useRouter();
  //console.log(`/restaurants/search?page=1&per_page=10&search_str=${encodeURIComponent(String(params.sst))}`);
  const [{ dataList, total_Pages }] = useCallContainerGet(
    params.sst && `/restaurants/search?page=1&per_page=10&search_str=${encodeURIComponent(String(params.sst))}`
  );

  const searchRestaurants = (sst:string) => {
    if (params.sst != sst)
        Taro.navigateTo({url:"../searchRestaurants/index?sst="+sst});
  }

  const searchDishes = (sst:string) => {
    Taro.navigateTo({url:"../searchDishes/index?sst="+sst});
  }
  return (
    <View style={{ padding: "10px" }}>
      <SearchBar onClick1={searchRestaurants} onClick2={searchDishes} defaultText={params.sst} defaultOption={0}/>
      {(dataList ?? []).map((restaurant) => (
        <RestaurantItem restaurant={restaurant} />
      ))}
    </View>
  );
}